package cn.ecut.controller;

import cn.ecut.utils.CodeUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping(value = "/index")
public class CodeController {
    @RequestMapping(value = "/Kaptcha", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> Kaptchatest(@RequestBody Map<String, String> map, HttpServletRequest request) {
        Map<String, Object> modelMap = new HashMap<>();
        if (!CodeUtil.checkVerifyCode(request, map.get("verifyCodeActual"))) {
            modelMap.put("success", false);
            modelMap.put("errMsg", "输入了错误的验证码");
            return modelMap;
        } else {
            modelMap.put("success", true);
            return modelMap;
        }
    }
}
